package com.gxa.p2p.service.impl;

import com.gxa.p2p.mapper.InvestMapper;
import com.gxa.p2p.pojo.Invest;
import com.gxa.p2p.pojo.LoanBidsDetail;
import com.gxa.p2p.service.InvestService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 投标记录表(Invest)表服务实现类
 */
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS, isolation = Isolation.DEFAULT)
@Service("investService")
public class InvestServiceImpl implements InvestService {

    @Resource
    private InvestMapper investMapper;

    /**
     * 带条件,且条件含有非空判断的全查询
     * @param map
     * @return list
     */
    @Override
    public List<LoanBidsDetail> findAll(Map<String,Object> map) {
        int page = ((Integer) map.get("page") - 1) * (Integer) map.get("limit");
        map.put("page",page);
        return investMapper.findAll(map);
    }

    /**
     * 查investList
     * @param map
     * @return List
     */
    @Override
    public List<LoanBidsDetail> findAll2(Map<String,Object> map) {
        return investMapper.findAll2(map);
    }

    /**
     * 计算带条件的数据总数
     * @param map
     * @return Integer
     */
    @Override
    public Integer dataSum(Map<String,Object> map) {
        return investMapper.dataSum(map);
    }

    /**
     * 新增数据
     * @param invest 实例对象
     * @return 影响行数
     */
    @Override
    @Transactional(readOnly = false, propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = {Throwable.class})
    public Integer insert(Invest invest) {
        return investMapper.insert(invest);
    }

    /**
     * 修改数据
     * @param invest 实例对象
     * @return 影响行数
     */
    @Override
    @Transactional(readOnly = false, propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = {Throwable.class})
    public Integer update(Invest invest) {
        return investMapper.update(invest);
    }

    /**
     * 通过主键删除数据
     * @param id 主键
     * @return 影响行数
     */
    @Override
    @Transactional(readOnly = false, propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = {Throwable.class})
    public Integer deleteById(Integer id) {
        return investMapper.deleteById(id);
    }
}